package cn.com.jonpad.demo08_cache_01.controller;

import cn.com.jonpad.demo08_cache_01.entity.Emploee;
import cn.com.jonpad.demo08_cache_01.service.EmploeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
public class EmploeeCtrl {
	@Autowired
	EmploeeService service;
	@GetMapping("emp/{id}")
	public Optional<Emploee> getOne(@PathVariable("id") Long id){
		Optional<Emploee> one = service.getOne(id);
		return one;
	}

	@PostMapping("emp")
	public Emploee update(@RequestBody Emploee id){
		return service.updateEmp(id);
	}

	@DeleteMapping("emp/{id}")
	public String update(@PathVariable("id") Long id){
		service.delete(id);
		return "success";
	}
	@DeleteMapping("emprm")
	public String rm(){
		service.rmAll();
		return "success";
	}

	@GetMapping("emp/name/{name}")
	public Emploee rm(@PathVariable("name") String name){
		return service.getEmpByName(name);
	}
}
